﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;
using Dict.Blo;

namespace UI
{
    public class UIunionFightLogItem : MonoBehaviour
    {
        public UILabel selfName;
        public UILabel enemyName;
        public TextureKit selfIcon;
        public TextureKit enemyIcon;
        public GameObject winUI;
        public GameObject loseUI;
        public GameObject movieBtn;
        long fightId;
        public void SetItem(ProtoBuf.Message.UFFightRecord item,bool isShowBtn)
        {
            var selfUnion = UIUnionFightRunMap.GetNetData().netBattle.GetUnoin(true);
            selfIcon.iconType = TextureIcon.HERO;
            enemyIcon.iconType = TextureIcon.HERO;
            var list = item.playerInfos;
            for (int i = 0;i < list.Count;)
            {
                var selfHero = DictHeroBlo.GetTableHero(list[i].mainHeroId);
                var enemyIndex = i + 1 % 2;
                var enemyHero = DictHeroBlo.GetTableHero(list[enemyIndex].mainHeroId);
                if (list[i].playerId == item.winPlayerId && list[i].unionId == selfUnion.unionId)
                {
                    selfName.text = list[i].nickName;
                    selfIcon.textureName = selfHero.iconName;
                    winUI.SetActive(true);
                    loseUI.SetActive(false);
                    enemyName.text = "[2f2f2f]" + list[enemyIndex].nickName + "[-]";
                    enemyIcon.textureName = enemyHero.iconName;
                    break;
                }
                else 
                {
                    selfName.text = "[2f2f2f]" + list[i].nickName + "[-]";
                    selfIcon.textureName = selfHero.iconName;
                    winUI.SetActive(false);
                    loseUI.SetActive(true);
                    enemyName.text = list[enemyIndex].nickName;
                    enemyIcon.textureName = enemyHero.iconName;
                    break;
                }
            }
            fightId = item.fightId;
            movieBtn.SetActive(isShowBtn);
        }

        public void OpenMoive()
        {
            UIUnionFightRunMap.GetNetData().SendCSUFFightRecordReplay(fightId);
        }
    }
}
